package com.runshu.newsmartark.util.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.runshu.newsmartark.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * <pre>
 *     time   : 2017/08/15
 *     desc   : 普通的类似ios的对话框
 *     version: 1.0   初始化
 *     params:
 *  <pre>
 */

public class CommonShowDialog extends Dialog {
    @BindView(R.id.img_dialog_show)
    ImageView mImgDialogShow;
    @BindView(R.id.tv_dialog_show)
    TextView mTvDialogShow;
    @BindView(R.id.tv_dialog_show_hint)
    TextView mTvDialogShowHint;
    private Context mContext;

    public CommonShowDialog(@NonNull Context context) {
        super(context, R.style.dialog_untran);
        mContext = context;
        setContentView(R.layout.dialog_show);
        ButterKnife.bind(this);
        this.setOnShowListener(new OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {

            }
        });
    }

    private String content;
    private String contentHint;

    private int imgShow;

    /**
     * 设置内容    默认为空
     *
     * @param content
     */
    public void setContent(String content) {
        this.content = content;
    }

    public void setContentHint(String contentHint) {
        this.contentHint = contentHint == null ? "" : contentHint;
        if(mTvDialogShowHint!=null)mTvDialogShowHint.setText(contentHint);
    }

    /**
     * 设置内容    默认为空
     *
     * @param imgShow
     */
    public void setImgShow(int imgShow) {
        this.imgShow = imgShow;
    }


    @Override
    public void show() {
        mTvDialogShow.setText(content);
        mImgDialogShow.setImageResource(imgShow);
        mTvDialogShowHint.setText(contentHint);
        super.show();
    }


    public void showLoding() {
        Animation rotateAnimation = AnimationUtils.loadAnimation(mContext, R.anim.rotate_anim);
        if (rotateAnimation != null) {
            mImgDialogShow.startAnimation(rotateAnimation);
        } else {
            mImgDialogShow.setAnimation(rotateAnimation);
            mImgDialogShow.startAnimation(rotateAnimation);
        }
    }

    public void closeLoding() {
        mImgDialogShow.clearAnimation();
    }


}
